# daily batch backup
# 1.get date
# 2.create script to compress to zip( over 2G size)
# 3.run script!
# 4.move to zip folder
# 5.delete before 7 days dmp files
# 

"""
    Updated History
    2. Updated by Allbory on Mar 2nd 2011
        * Added \n to every write() method.
        
    1. Updated by Allbory on Feb 26th 2011
        * try/catch exception was added.
        * Save log file.
        
"""

import datetime

# flag can tell where you are now.
flag = "10"

# get today and try to return as string
today = datetime.datetime.now()

print "Current year: %d" % today.year
print "Current year: %d" % today.month
print "Current year: %d" % today.day

month_str = str(today.month)
day_str = str(today.day)

# months manipulation
if len(month_str) == 1:
    month_str = "0" + month_str
else:
    month_str = month_str
  
# day manipulation
if len(day_str) == 1:
    day_str = "0" + day_str
else:
    day_str = day_str  

today_str = str(today.year) + month_str + day_str
tm_str = str(today.year) + month_str

print today_str

#Genrate log file
try:
    flag = "11"
    py_log = open(today_str+"_py.log",'w')
    flag = "12"
    current_time = datetime.datetime.now()
    flag = "13" 
    py_log.write (str(current_time) + ">>part1>>Today is : " + today_str + "\n")
    flag = "14"
    py_log.write (str(current_time) + ">>part1>>Generating BZS file getting started...\n")
    flag = "15"
except:
    py_log.write (">>part1>>Exception occurred while open py.log file..." + flag + "\n")

#Generate BSZ script file
f = open(today_str+".bzs",'w')
f.write(";BreadZip Script Version 1\n")
f.write("Mode=Compress\n")
f.write("ArchiveFile=C:\\Temp BackupDB\\"+ tm_str +"\\"+ today_str +"<DATE><TIME>.zip\n")
f.write("Progress.Caption=dmp backup\n")
f.write("Files.RootPath=D:\\backup\\db\\\n")
f.write("Files.Count=17\n")
f.write("Files.0="+ today_str +".dmp\n")
f.write("Files.1="+ today_str +".log\n")
f.close()

current_time = datetime.datetime.now()
py_log.write (str(current_time) + ">>part1>>Generating BZS file getting started...\n")
current_time = datetime.datetime.now()
py_log.write (str(current_time) + ">>part1>>BackupScript1 has finished...\n")
py_log.close()